package Interfaz;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import Mundo.estudiante;


/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class ventanaPrincipal extends javax.swing.JFrame implements ActionListener{	private JLabel codigo;
private JLabel jLabelSalida;
private estudiante miEstudiante= new estudiante();  
private JButton jButtonCodigo;
private JButton jButtonDefinitiva;
private JButton jButtonGuardar;
private JTextField jTextFieldNota2;
private JTextField jTextFieldNota1;
private JTextField jTextFieldNombre1;
private JTextField jTextField;
private JLabel jLabel1nota2;
private JLabel jLabel1nota1;
private JTextField jTextFieldCodigo;
private JLabel jLabelNombre;

/**
 * Auto-generated main method to display this JFrame
 */
public static void main(String[] args) {
	SwingUtilities.invokeLater(new Runnable() {
		public void run() {
			ventanaPrincipal inst = new ventanaPrincipal();
			inst.setLocationRelativeTo(null);
			inst.setVisible(true);
		}
	});
}

public ventanaPrincipal() {
	super();
	initGUI();
}

private void initGUI() {
	try {
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		getContentPane().setLayout(null);
		{
			codigo = new JLabel();
			getContentPane().add(codigo);
			codigo.setText("codigo");
			codigo.setBounds(26, 27, 43, 15);
		}
		{
			jLabelNombre = new JLabel();
			getContentPane().add(jLabelNombre);
			jLabelNombre.setText("Nombre");
			jLabelNombre.setBounds(26, 59, 55, 20);
		}
		{
			jLabel1nota1 = new JLabel();
			getContentPane().add(jLabel1nota1);
			jLabel1nota1.setText("Nota1");
			jLabel1nota1.setBounds(26, 91, 47, 15);
		}
		{
			jLabel1nota2 = new JLabel();
			getContentPane().add(jLabel1nota2);
			jLabel1nota2.setText("Nota2");
			jLabel1nota2.setBounds(26, 118, 47, 17);
		}
		{
			jTextFieldNombre1 = new JTextField();
			getContentPane().add(jTextFieldNombre1);
			jTextFieldNombre1.setBounds(99, 57, 90, 20);
		}
		{
			jTextFieldNota1 = new JTextField();
			getContentPane().add(jTextFieldNota1);
			jTextFieldNota1.setBounds(99, 88, 90, 21);
		}
		{
			jTextFieldNota2 = new JTextField();
			getContentPane().add(jTextFieldNota2);
			jTextFieldNota2.setBounds(102, 117, 90, 18);
		}
		{
			jButtonGuardar = new JButton();
			getContentPane().add(jButtonGuardar);
			jButtonGuardar.setBounds(26, 168, 73, 23);
			jButtonGuardar.setText("Guardar");
			jButtonGuardar.addActionListener(this);
		}
		{
			jButtonDefinitiva = new JButton();
			getContentPane().add(jButtonDefinitiva);
			jButtonDefinitiva.setBounds(130, 169, 89, 22);
			jButtonDefinitiva.setText("Definitiva");
			jButtonDefinitiva.addActionListener(this);
		}
		{
			jButtonCodigo = new JButton();
			getContentPane().add(jButtonCodigo);
			jButtonCodigo.setText("Codigo");
			jButtonCodigo.setBounds(254, 169, 68, 22);
			jButtonCodigo.addActionListener(this);
		}
		{
			jLabelSalida = new JLabel();
			getContentPane().add(jLabelSalida);
			jLabelSalida.setBounds(46, 233, 271, 24);
		}
		{
			jTextFieldCodigo = new JTextField();
			getContentPane().add(jTextFieldCodigo);
			jTextFieldCodigo.setBounds(99, 24, 90, 27);
		}
		pack();
		setSize(400, 300);
	} catch (Exception e) {
		//add your error handling code here
		e.printStackTrace();
	}
}

@Override
public void actionPerformed(ActionEvent e) 
{
	String codigo="", nombre="";
	double nota1, nota2;
    double def=0;
 	String cod="";

    if(e.getSource()==jButtonGuardar)
	{codigo=jTextFieldCodigo.getText();
	 nombre=jTextFieldNombre1.getText();
	 nota1=Integer.parseInt(jTextFieldNota1.getText());
	 nota2=Integer.parseInt(jTextFieldNota2.getText());
	 miEstudiante.setCodigo(codigo);
	 miEstudiante.setNombre(nombre);
	 miEstudiante.setNota1(nota1);
	 miEstudiante.setNota2(nota2);
	}
    else
    	if(e.getSource()==jButtonDefinitiva)
    	{
    		def=miEstudiante.publicarDefinitiva();
    		jLabelSalida.setText(""+def);
    	}
    	else
    		if(e.getSource()==jButtonCodigo)
        	{
        		cod=miEstudiante.getCodigo();
        		jLabelSalida.setText(""+cod);
        	}

}

}
